package com.baseweb.webadmin.core.model.mapper;

import com.baseweb.webadmin.core.model.pojo.ByUserBizSchedule;
import com.baseweb.webadmin.core.model.pojo.ByUserBizScheduleExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.joda.time.DateTime;

public interface ByUserBizScheduleMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_biz_schedule
     *
     * @mbggenerated Sat Apr 22 10:12:22 CST 2017
     */
    int countByExample(ByUserBizScheduleExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_biz_schedule
     *
     * @mbggenerated Sat Apr 22 10:12:22 CST 2017
     */
    int deleteByExample(ByUserBizScheduleExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_biz_schedule
     *
     * @mbggenerated Sat Apr 22 10:12:22 CST 2017
     */
    @Delete({
        "delete from by_user_biz_schedule",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Delete({
        "delete from by_user_biz_schedule",
        "where schedule_type = #{scheduleType, jdbcType=INTEGER} ",
            "and schedule_date = #{scheduleDate, jdbcType=DATE,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2DateTypeHandler} ",
            "and user_id = #{userId, jdbcType=INTEGER}"
    })
    int deleteByConditions(ByUserBizSchedule record);

    @Select({
            "select id from by_user_biz_schedule",
            "where schedule_type = #{scheduleType, jdbcType=INTEGER} ",
            "and schedule_date = #{scheduleDate, jdbcType=DATE,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2DateTypeHandler} ",
            "and user_id = #{userId, jdbcType=INTEGER}"
    })
    Integer selectIdByConditions(ByUserBizSchedule record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_biz_schedule
     *
     * @mbggenerated Sat Apr 22 10:12:22 CST 2017
     */
    @Insert({
        "insert into by_user_biz_schedule (user_id, schedule_date, ",
        "schedule_type, status, ",
        "create_time, ",
        "update_time, ",
        "order_id, order_detail_id, ",
        "order_by)",
        "values (#{userId,jdbcType=INTEGER}, #{scheduleDate,jdbcType=DATE,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2DateTypeHandler}, ",
        "#{scheduleType,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, ",
        "#{createTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
        "#{updateTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
        "#{orderId,jdbcType=INTEGER}, #{orderDetailId,jdbcType=INTEGER}, ",
        "#{orderBy,jdbcType=INTEGER})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(ByUserBizSchedule record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_biz_schedule
     *
     * @mbggenerated Sat Apr 22 10:12:22 CST 2017
     */
    int insertSelective(ByUserBizSchedule record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_biz_schedule
     *
     * @mbggenerated Sat Apr 22 10:12:22 CST 2017
     */
    List<ByUserBizSchedule> selectByExample(ByUserBizScheduleExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_biz_schedule
     *
     * @mbggenerated Sat Apr 22 10:12:22 CST 2017
     */
    @Select({
        "select",
        "id, user_id, schedule_date, schedule_type, status, create_time, update_time, ",
        "order_id, order_detail_id, order_by",
        "from by_user_biz_schedule",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    ByUserBizSchedule selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_biz_schedule
     *
     * @mbggenerated Sat Apr 22 10:12:22 CST 2017
     */
    int updateByExampleSelective(@Param("record") ByUserBizSchedule record, @Param("example") ByUserBizScheduleExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_biz_schedule
     *
     * @mbggenerated Sat Apr 22 10:12:22 CST 2017
     */
    int updateByExample(@Param("record") ByUserBizSchedule record, @Param("example") ByUserBizScheduleExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_biz_schedule
     *
     * @mbggenerated Sat Apr 22 10:12:22 CST 2017
     */
    int updateByPrimaryKeySelective(ByUserBizSchedule record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_biz_schedule
     *
     * @mbggenerated Sat Apr 22 10:12:22 CST 2017
     */
    @Update({
        "update by_user_biz_schedule",
        "set user_id = #{userId,jdbcType=INTEGER},",
          "schedule_date = #{scheduleDate,jdbcType=DATE,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2DateTypeHandler},",
          "schedule_type = #{scheduleType,jdbcType=INTEGER},",
          "status = #{status,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
          "order_id = #{orderId,jdbcType=INTEGER},",
          "order_detail_id = #{orderDetailId,jdbcType=INTEGER},",
          "order_by = #{orderBy,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(ByUserBizSchedule record);

    /**
     * 根据Userid，时间段查询所有的档期
     * */
    @Select({
            "select * ",
            "from by_user_biz_schedule",
            "where user_id = #{0} and (schedule_date BETWEEN #{1} and #{2} )"
    })
    @ResultMap("BaseResultMap")
    List<ByUserBizSchedule> findAllByUserIdDate(int userId,String startTime,String endTime);

    /**
     * 修改档期为不接单
     * */
    @Update({
            "update by_user_biz_schedule",
            "set status = #{1} ",
            "where id = #{0}"
    })
    int udpateStatusById(int id,int status);
}